#pragma once

#include <arpa/inet.h>
#include <netinet/in.h>
#include <string>

// 封装 socket 的 IP 和端口
class InetAddress {
public:
  explicit InetAddress(const uint16_t port, const std::string& ip = "127.0.0.1");
  explicit InetAddress(const sockaddr_in& addr) : m_addr(addr) {}
  explicit InetAddress() = default;

  std::string toIp() const;
  std::string toIpPort() const;
  uint16_t toPort() const;
  const sockaddr_in* getSockAddr() const { return &m_addr; }
  void setSockAddr(const sockaddr_in& addr) { m_addr = addr; }
private:
  sockaddr_in m_addr;
};